import Suggestion from '../components/suggestion';
import * as UserAction from 'actions/user';
import * as ReactRedux from 'react-redux';

const mapStateToProps = (state) => {
  return {
    options: state.suggestUser.map(user => {
      let text = user.email;
      if (user.nick) {
        text = `${text}(${user.nick})`;
      }
      return {
        value: user.id,
        text
      };
    }),
    placeholder: '输入用户邮箱地址来查找用户'
  };
};

const mapDispatchToProps = (dispatch) => {
  return {
    onSuggest: (value) => {
      return dispatch(UserAction.suggest(value));
    }
  };
};

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(Suggestion);
